package com.huabo.audit.controller;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfig;

import com.alibaba.fastjson.JSONObject;
import com.hbfk.util.JsonBean;
import com.hbfk.util.ResponseFormat;
import com.huabo.audit.oracle.entity.TblNbsjAuditprogramEntity;
import com.huabo.audit.oracle.entity.TblNbsjBugCriterion;
import com.huabo.audit.oracle.entity.TblNbsjInnerrule;
import com.huabo.audit.oracle.entity.TblNbsjOuterruleEntity;
import com.huabo.audit.oracle.entity.TblNbsjTargettypeEntity;
import com.huabo.audit.oracle.entity.TblNbsjTempleteEntity;
import com.huabo.audit.oracle.entity.TblNbsjType;
import com.huabo.audit.oracle.entity.TblOrganization;
import com.huabo.audit.oracle.entity.TblOtherarticle;
import com.huabo.audit.oracle.vo.TblGkProjectVo;
import com.huabo.audit.oracle.vo.TblGkQuestionVo;
import com.huabo.audit.oracle.vo.TblGkZgQuestionVo;
import com.huabo.audit.oracle.vo.TblNbsjInnerRuleVo;
import com.huabo.audit.oracle.vo.TblNbsjTempleteVo;
import com.huabo.audit.oracle.vo.TblOtherarticleVo;
import com.huabo.audit.service.AttachmentService;
import com.huabo.audit.service.TblAttachmentService;
import com.huabo.audit.service.TblNbsjAuditprogramService;
import com.huabo.audit.service.TblNbsjBugCriterionService;
import com.huabo.audit.service.TblNbsjInnerRuleService;
import com.huabo.audit.service.TblNbsjOuterruleService;
import com.huabo.audit.service.TblNbsjProjectService;
import com.huabo.audit.service.TblNbsjTargettypeService;
import com.huabo.audit.service.TblNbsjTempleteService;
import com.huabo.audit.service.TblNbsjTypeService;
import com.huabo.audit.service.TblOrganizaService;
import com.huabo.audit.service.TblOtherarticleService;
import com.huabo.audit.util.FileUtil;
import com.huabo.audit.util.FreeMarkerUtil;
import com.huabo.audit.util.R;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;

/**
 * 审计工作台
 */
@RestController
@Slf4j
@Api(value = "审计工作台、审计管控分析", tags = { "审计工作台、审计管控分析" })
@RequestMapping(value = "/nbsjworkSpace")
public class NbsjWorkSpaceController {
	
	@Resource
	public AttachmentService attachmentService;
	@Resource
	public TblNbsjTempleteService tblNbsjTempleteService;
	@Resource
	public TblNbsjTargettypeService tblNbsjTargettypeService;
	@Resource
	public TblNbsjAuditprogramService tblNbsjAuditprogramService;
	@Resource
	public TblNbsjOuterruleService tblNbsjOuterruleService;
	@Resource
	public TblNbsjInnerRuleService tblNbsjInnerRuleService;
	@Resource
	public TblNbsjBugCriterionService  tblNbsjBugCriterionService;
	@Resource
    private TblNbsjTypeService tblNbsjTypeService;
	@Resource
	public FreeMarkerConfig freeMarkerConfig;
    @Resource
    public TblOrganizaService tblOrganizaService;
    @Resource
    public TblOtherarticleService tblOtherarticleService;
	@Resource
	public TblNbsjProjectService tblnbsjProjectService;
	
	@Resource
	private TblAttachmentService tblAttachmentService;
    
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");//注意月份是MM
	
	
    
    @RequestMapping(value = "/getNbsjTempletePageList", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation("审计模板-列表页")
    @ApiOperationSupport(order = 1)
    public JsonBean getNbsjTempletePageList(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
   		@ApiParam(name="pageNumber",value="分页当前页数",required=false)@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
   		@ApiParam(name="pageSize",value="每页记录数",required=false)@RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
   		TblNbsjTempleteVo tblNbsjTempleteVo) {
    	JsonBean jsonBean = null;
    	try {
    		tblNbsjTempleteVo.setTempType("0");
			jsonBean = tblNbsjTempleteService.selectNbsjTempleteListByPageInfo(token,pageNumber,pageSize,tblNbsjTempleteVo);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
    @RequestMapping(value = "/getNbsjZyTempletePageList", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation("指引模板-列表页")
    @ApiOperationSupport(order = 1)
    public JsonBean getNbsjZyTempletePageList(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="pageNumber",value="分页当前页数",required=false)@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
    		@ApiParam(name="pageSize",value="每页记录数",required=false)@RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
    		TblNbsjTempleteVo tblNbsjTempleteVo) {
    	JsonBean jsonBean = null;
    	try {
    		tblNbsjTempleteVo.setTempType("1");
    		jsonBean = tblNbsjTempleteService.selectNbsjTempleteListByPageInfo(token,pageNumber,pageSize,tblNbsjTempleteVo);
    	} catch (Exception e) {
    		e.printStackTrace();
    	}
    	return jsonBean;
    }
    @RequestMapping(value = "/getNbsjjyTempletePageList", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation("审计经验库-列表页")
    @ApiOperationSupport(order = 1)
    public JsonBean getNbsjjyTempletePageList(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="pageNumber",value="分页当前页数",required=false)@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
    		@ApiParam(name="pageSize",value="每页记录数",required=false)@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
    		TblNbsjTempleteVo tblNbsjTempleteVo) {
    	JsonBean jsonBean = null;
    	try {
    		tblNbsjTempleteVo.setTempType("2");
    		jsonBean = tblNbsjTempleteService.selectNbsjTempleteListByPageInfo(token,pageNumber,pageSize,tblNbsjTempleteVo);
    	} catch (Exception e) {
    		e.printStackTrace();
    	}
    	return jsonBean;
    }
    @RequestMapping(value = "/mergeNbsjTemplete", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "审计模板-新增、修改")
    @ApiOperationSupport(order = 2)
	public JsonBean mergeNbsjTemplete(HttpServletRequest request
			,@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token
			,@ApiParam(name="orgids",value="适用机构(格式：1,2,3,4)",required=true) @RequestHeader("orgids")String orgids
			,@ApiParam(name="templete",value="审计模板实体",required=true)TblNbsjTempleteEntity templete)throws Exception{
		 JsonBean jsonBean = null;
			try {
				jsonBean = this.tblNbsjTempleteService.mergeNbsjTempleteInfo(templete,token,orgids);
			} catch (Exception e) {
				ResponseFormat.retParam(1,1000,e.getMessage());
			}
			return jsonBean;
	}
    @RequestMapping(value = "/updateTempleteStatus", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "审计模板-修改状态")
    @ApiOperationSupport(order = 3)
    public JsonBean updateStatus(HttpServletRequest request
    		,@ApiParam(name="templeteId",value="模板主键",required=true) @RequestHeader("templeteId")String templeteId)throws Exception{
    	JsonBean jsonBean = null;
    	try {
    		jsonBean = this.tblNbsjTempleteService.updateStatus(templeteId);
    	} catch (Exception e) {
    		ResponseFormat.retParam(1,1000,e.getMessage());
    	}
    	return jsonBean;
    }
    @RequestMapping(value = "/copyTemplete", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "模板复制功能")
    @ApiOperationSupport(order = 3)
    public JsonBean copyTemplete(HttpServletRequest request,@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token
    		,@ApiParam(name="templeteId",value="主键",required=true) @RequestHeader("templeteId")String templeteId
    		,@ApiParam(name="copytype",value="复制类型(copytype=0，复制为审计模板；copytype=1，复制为指引模板；copytype=2，复制为审计经验库)",required=true) @RequestHeader("copytype")Integer copytype
    		)throws Exception{
    	JsonBean jsonBean = null;
    	try {
    		jsonBean = this.tblNbsjTempleteService.copyTemplete(templeteId,copytype,token);
    	} catch (Exception e) {
    		ResponseFormat.retParam(1,1000,e.getMessage());
    	}
    	return jsonBean;
    }
    @RequestMapping(value = "/selectTempleteInfo", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "审计模板-查询单个信息")
    @ApiOperationSupport(order = 4)
    public JsonBean selectInfo(HttpServletRequest request
    		,@ApiParam(name="templeteId",value="主键",required=true) @RequestHeader("templeteId")String templeteId)throws Exception{
    	JsonBean jsonBean = null;
    	try {
    		jsonBean = this.tblNbsjTempleteService.selectInfo(templeteId);
    	} catch (Exception e) {
    		ResponseFormat.retParam(1,1000,e.getMessage());
    	}
    	return jsonBean;
    }
    @RequestMapping(value = "/deleteTempleteInfo", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "审计模板-删除")
    @ApiOperationSupport(order = 5)
    public JsonBean deleteInfo(HttpServletRequest request
    		,@ApiParam(name="templeteId",value="主键",required=true) @RequestHeader("templeteId")String templeteId)throws Exception{
    	JsonBean jsonBean = null;
    	try {
    		jsonBean = this.tblNbsjTempleteService.deleteInfo(templeteId);
    	} catch (Exception e) {
    		ResponseFormat.retParam(1,1000,e.getMessage());
    	}
    	return jsonBean;
    }
    @RequestMapping(value = "/mergeTblNbsjTarget", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "审计模板目录-新增、修改")
    @ApiOperationSupport(order = 6)
	public JsonBean mergeTblNbsjTargettype(HttpServletRequest request
			,@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token
			,@ApiParam(name="target",value="审计模板目录实体",required=true)TblNbsjTargettypeEntity target)throws Exception{
		 JsonBean jsonBean = null;
			try {
				jsonBean = tblNbsjTargettypeService.mergeNbsjTargettypInfo(target,token);
			} catch (Exception e) {
				ResponseFormat.retParam(1,1000,e.getMessage());
			}
			return jsonBean;
	}
    @RequestMapping(value = "/selectNbsjTargetInfo", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "审计模板目录-查询单个信息")
    @ApiOperationSupport(order = 7)
    public JsonBean selectNbsjTargetInfo(HttpServletRequest request
    		,@ApiParam(name="targetId",value="审计目标id",required=true) @RequestHeader("targetId")String targetId)throws Exception{
    	JsonBean jsonBean = null;
    	try {
    		jsonBean = this.tblNbsjTargettypeService.selectInfo(targetId);
    	} catch (Exception e) {
    		ResponseFormat.retParam(1,1000,e.getMessage());
    	}
    	return jsonBean;
    }
    @RequestMapping(value = "/deleteNbsjTarget", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "审计模板目录-删除")
    @ApiOperationSupport(order = 8)
    public JsonBean deleteNbsjTarget(HttpServletRequest request
    		,@ApiParam(name="targetId",value="审计目标id",required=true) @RequestHeader("targetId")String targetId)throws Exception{
    	JsonBean jsonBean = null;
    	try {
    		jsonBean = this.tblNbsjTargettypeService.deleteInfo(targetId);
    	} catch (Exception e) {
    		ResponseFormat.retParam(1,1000,e.getMessage());
    	}
    	return jsonBean;
    }
    @RequestMapping(value = "/findNbsjTargetTree", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "审计模板目录-左侧树结构")
    @ApiOperationSupport(order = 8)
    public JsonBean findNbsjTargetTree(HttpServletRequest request
    		,@ApiParam(name="templeteId",value="模板id",required=true) @RequestHeader("templeteId")String templeteId
    		,@ApiParam(name="nodeId",value="父节点id") @RequestHeader("nodeId")String nodeId)throws Exception{
    	JsonBean jsonBean = null;
    	try {
    		jsonBean = this.tblNbsjTargettypeService.findNbsjTargetTree(templeteId,nodeId);
    	} catch (Exception e) {
    		ResponseFormat.retParam(1,1000,e.getMessage());
    	}
    	return jsonBean;
    }
    @RequestMapping(value = "/findNbsjTargetTree2", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "审计模板目录-左侧树结构2")
    @ApiOperationSupport(order = 8)
    public String findNbsjTargetTree2(HttpServletRequest request
    		,@ApiParam(name="templeteId",value="模板id",required=true) @RequestHeader("templeteId")String templeteId
    		)throws Exception{
        String result = null;
         result = tblNbsjTargettypeService.getTargetTree(templeteId);
        return result;
    }
    @RequestMapping(value = "/getTblNbsjAuditprogramPageList", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation("审计指引-列表页")
    @ApiOperationSupport(order = 9)
    public JsonBean getTblNbsjAuditprogramPageList(HttpServletRequest request
    		,@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token
    		,@ApiParam(name="pageNumber",value="分页当前页数",required=false)@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber
    		,@ApiParam(name="pageSize",value="每页记录数",required=false)@RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize
    		,@ApiParam(name="templeteId",value="模板id",required=true) @RequestHeader("templeteId")String templeteId
    		,@ApiParam(name="targetId",value="所属目录id",required=false) @RequestHeader("targetId")String targetId) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = tblNbsjAuditprogramService.selectTblNbsjAuditprogramListByPageInfo(token,pageNumber,pageSize,templeteId,targetId);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
    @RequestMapping(value = "/mergeTblNbsjAuditprogram", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "审计指引-新增、修改")
    @ApiOperationSupport(order = 10)
	public JsonBean mergeTblNbsjAuditprogram(HttpServletRequest request
			,@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token
			,@ApiParam(name="program",value="审计指引实体",required=true)TblNbsjAuditprogramEntity program)throws Exception{
		 JsonBean jsonBean = null;
			try {
				jsonBean = tblNbsjAuditprogramService.mergeTblNbsjAuditprogramInfo(program,token);
			} catch (Exception e) {
				ResponseFormat.retParam(1,1000,e.getMessage());
			}
			return jsonBean;
	}
    @RequestMapping(value = "/selectNbsjAuditprogram", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "审计指引-查询单个信息")
    @ApiOperationSupport(order = 11)
    public JsonBean selectNbsjAuditprogram(HttpServletRequest request
    		,@ApiParam(name="programId",value="审计指引id",required=true) @RequestHeader("programId")String programId)throws Exception{
    	JsonBean jsonBean = null;
    	try {
    		jsonBean = this.tblNbsjAuditprogramService.selectInfo(programId);
    	} catch (Exception e) {
    		ResponseFormat.retParam(1,1000,e.getMessage());
    	}
    	return jsonBean;
    }
    @RequestMapping(value = "/deleteNbsjAuditprogram", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "审计指引-删除")
    @ApiOperationSupport(order = 12)
    public JsonBean deleteNbsjAuditprogram(HttpServletRequest request
    		,@ApiParam(name="programId",value="审计指引id",required=true) @RequestHeader("programId")String programId)throws Exception{
    	JsonBean jsonBean = null;
    	try {
    		jsonBean = this.tblNbsjAuditprogramService.deleteInfo(programId);
    	} catch (Exception e) {
    		ResponseFormat.retParam(1,1000,e.getMessage());
    	}
    	return jsonBean;
    }
	@RequestMapping(value = "/getNbsjTypeListPage", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation("审计类型-列表页")
    @ApiOperationSupport(order = 29)
    public JsonBean getNbsjTypeListPage(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
   		@ApiParam(name="pageNumber",value="分页当前页数",required=false)@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
   		@ApiParam(name="pageSize",value="每页记录数",required=false)@RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = this.tblNbsjTypeService.getNbsjTypeListPage(token,pageNumber,pageSize);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
	@RequestMapping(value = "/sjtype/sjtypeinfo", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "审计类型-详情页")
    @ApiOperationSupport(order = 30)
	public JsonBean sjtype_update(@RequestParam(value = "typeid", required = true)@ApiParam(name="typeid",value="审计类型id",required=true)String typeid,
			 @ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token)throws Exception{
		     JsonBean jsonBean = null;
			try {
				jsonBean = this.tblNbsjTypeService.SelectNbsjType(typeid, token);
			} catch (Exception e) {
				ResponseFormat.retParam(1,1000,e.getMessage());
			}
			return jsonBean;
	}
    @RequestMapping(value = "/sjtype/sjtype_save", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "审计类型-新增及修改")
    @ApiOperationSupport(order = 31)
	public JsonBean sjtype_save(HttpServletRequest request,@ApiParam(name="nbsjType",value="审计类型实体",required=true)TblNbsjType nbsjType,
			 @ApiParam(name="token",value="登录用户token",required=false) @RequestHeader("token")String token)throws Exception{
	     JsonBean jsonBean = null;
			try {
				jsonBean = this.tblNbsjTypeService.saveNbsjType(nbsjType, token);
			} catch (Exception e) {
				ResponseFormat.retParam(1,1000,e.getMessage());
			}
			return jsonBean;
	} 
 
    @RequestMapping(value = "/sjtype/sjtype_delete", produces = "application/json; charset=utf-8", method = {RequestMethod.GET})
	@ApiOperation(value = "审计类型-删除")
    @ApiOperationSupport(order = 32)
	public JsonBean removePlanProjectInfo(HttpServletRequest request,
			 @RequestParam(value = "typeid", required = true)@ApiParam(name="typeid",value="审计类型id",required=true)String typeid,
			 @ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token)throws Exception{
        JsonBean jsonBean = null;
		try {
			jsonBean = this.tblNbsjTypeService.delNbsjType(typeid, token);
		} catch (Exception e) {
			ResponseFormat.retParam(1,1000,e.getMessage());
		}
		return jsonBean;
	}
    @RequestMapping(value = "/getNbsjBugCriterionPageList", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation("缺陷标准-列表页")
    @ApiOperationSupport(order = 33)
    public JsonBean getNbsjBugCriterionPageList(HttpServletRequest request
    		,@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token
    		,@ApiParam(name="pageNumber",value="分页当前页数",required=false)@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber
    		,@ApiParam(name="pageSize",value="每页记录数",required=false)@RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean= tblNbsjBugCriterionService.selectNbsjBugCriterionByPageInfo(token, pageNumber, pageSize);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
	@RequestMapping(value = "/gzdg/def_quexian_save", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "缺陷标准-新增及修改")
    @ApiOperationSupport(order = 33)
	public JsonBean def_quexian_save(HttpServletRequest request,@ApiParam(name="nbsjType",value="缺陷标准实体",required=true)TblNbsjBugCriterion bug,
			 @ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token)throws Exception{
    	JsonBean jsonBean = null;
			try {
				jsonBean = this.tblNbsjBugCriterionService.saveNbsjBugCriterion(bug, token);
			} catch (Exception e) {
				ResponseFormat.retParam(1,1000,e.getMessage());
			}
			return jsonBean;
	}
    
	
	@RequestMapping(value = "/gzdg/def_quexian_update", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "缺陷标准-查询单个信息")
    @ApiOperationSupport(order = 34)
	public JsonBean def_quexian_update(@RequestParam(value = "bugcriid", required = true)@ApiParam(name="bugcriid",value="缺陷id",required=true)String bugcriid,
			 @ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token)throws Exception{
		     JsonBean jsonBean = null;
			try {
				jsonBean = this.tblNbsjBugCriterionService.SelectNbsjBugCriterion(bugcriid, token);
			} catch (Exception e) {
				ResponseFormat.retParam(1,1000,e.getMessage());
			}
			return jsonBean;
	} 
    
	
	
    @RequestMapping(value = "/gzdg/def_quexian_del", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "缺陷标准-删除")
    @ApiOperationSupport(order = 35)
	public JsonBean def_quexian_del(HttpServletRequest request,
			 @RequestParam(value = "bugcriid", required = true)@ApiParam(name="bugcriid",value="缺陷标准id",required=true)String bugcriid,
			 @ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token)throws Exception{
	     JsonBean jsonBean = null;
		try {
			jsonBean = this.tblNbsjBugCriterionService.delNbsjBugCriterion(bugcriid, token);
		} catch (Exception e) {
			ResponseFormat.retParam(1,1000,e.getMessage());
		}
		return jsonBean;
	}
	

	//法律规章  新增、修改、删除、导出、预览、列表页
    @GetMapping("/gkzk/mag/out_list")
    @ApiOperation("法律规章列表分页功能")
    @ApiOperationSupport(order = 36)
    public JsonBean getAuditPlanPageList(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
   		@ApiParam(name="pageNumber",value="分页当前页数",required=false)@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
   		@ApiParam(name="pageSize",value="每页记录数",required=false)@RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
   		@ApiParam(name="prulenumber",value="审计查询条件-发文字号",required=false) @RequestParam(value = "prulenumber", required = false) String prulenumber,
		@ApiParam(name="prulename",value="审计查询条件-文件名称",required=false) @RequestParam(value = "prulename", required = false) String prulename,
		@ApiParam(name="content",value="审计查询条件-内容",required=false) @RequestParam(value = "content", required = false) String content,
		@ApiParam(name="type",value="法律规章类别条件  审计：nbsj",required=true) @RequestParam(value = "type", required = true) String type) {
    	JsonBean jsonBean = null;
    	try {
    		TblNbsjOuterruleEntity paream = new TblNbsjOuterruleEntity();
    		if (content != null && content.trim().length() > 0) {
    			paream.setBodyinfo(content);
    		}
    		if (prulename != null && prulename.length() > 0) {
    			paream.setRulename(prulename);
    		}
    		if (prulenumber != null && prulenumber.length() > 0) {
    			paream.setRulenumber(prulenumber);
    		}
			jsonBean = tblNbsjOuterruleService.findOuterRuleList(token,pageNumber,pageSize,paream,type);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
	 
  
    @GetMapping("/gkzk/mag/modify_out")
    @ApiOperation("法律规章-详情及修改获取数据及预览获取数据返回类中的bodyinfo")
    @ApiOperationSupport(order = 37)
    public JsonBean getAuditPlanInfo(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="outrulid",value="法律规章主键",required=true)@RequestParam(value = "outrulid", required = true) String outrulid) {
    	JsonBean jsonBean = null;
    	try { 
			jsonBean = tblNbsjOuterruleService.findById(token,outrulid);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
	 
    
    @GetMapping("/gkzk/mag/delete_out")
    @ApiOperation("法律规章-删除数据")
    @ApiOperationSupport(order = 38)
    public JsonBean delete_out(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="outrulid",value="法律规章主键",required=true)@RequestParam(value = "outrulid", required = true) String outrulid) {
        Map<String,Object> resultMap = new HashMap<String,Object>(0);
    	try { 
    		resultMap = tblNbsjOuterruleService.delete(token,outrulid);
		} catch (Exception e) {
//			resultMap.put("code", "0");
//			resultMap.put("msg", "该条法律章程正在使用！");
			e.printStackTrace();
			return new JsonBean(0, "该条法律章程正在使用！", null);
			
		}
    	return ResponseFormat.retParam(1,200,resultMap);
//        return resultMap.toString();
    }
	
    
    @RequestMapping(value = "/gkzk/mag/save_modify_out", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "法律规章新增或修改")
    @ApiOperationSupport(order = 39)
	public JsonBean mergePlanProjectManageInfo(HttpServletRequest request,@ApiParam(name="outer",value="法律规章项目实体",required=true)TblNbsjOuterruleEntity outer,
			 @ApiParam(name="outerId",value="法律规章主键 ，如果主键为空则根据编码新增法律规章信息",required=false) @RequestParam(value = "outerId", required = false) BigDecimal outerId,
			 @ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token, 
			 @ApiParam(name="attIds",value="附件主键数组 示例1,2,3,4",required=false) @RequestParam(value="attIds", required = false) String attIds)throws Exception{
		 JsonBean jsonBean = null;
			try {
				jsonBean = this.tblNbsjOuterruleService.mergeOuterruleInfo(token,outer, outerId,attIds);
			} catch (Exception e) {
				ResponseFormat.retParam(1,1000,e.getMessage());
			}
			return jsonBean;
	} 
    //==
    /**
	 * 法律规章-附件列表
	 */
    @GetMapping("/gkzk/mag/out_file_list")
	@ApiOperation(value = "法律规章-附件列表")
	public JsonBean out_file_list(HttpServletRequest request, 
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "outerId", value = "业务主键", required = false) @RequestParam(value = "outerId", required = false) Integer outerId) {

		JsonBean jsonBean = null;
		try {
			jsonBean = this.tblAttachmentService.outFileList(token,outerId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
    /**
     * 法律规章-附件删除
     */
    @GetMapping("/gkzk/mag/out_file_del")
    @ApiOperation(value = "法律规章-附件删除")
    public R out_file_del(HttpServletRequest request, HttpServletResponse response,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="attId",value="附件主键ID",required=true) @RequestParam("attId") String attId) throws Exception {
    	return this.tblNbsjOuterruleService.removeAttInfoByAttId(token, attId);
    }
    
    
    /**
     * 法律规章-导出
     * @param request
     * @param response
     * @param id
     * @throws Exception
     */
    @RequestMapping(value = "/expOuterRuleFile", produces = "application/json; charset=utf-8", method = {RequestMethod.GET})
   	@ApiOperation(value = "法律规章导出")
    @ApiOperationSupport(order = 40)
	public void expOuterRuleFile(HttpServletRequest request, HttpServletResponse response,
			@ApiParam(name="id",value="主键",required=true) @RequestHeader("id")String id)throws Exception{
		Map<String, String> map = new HashMap<String,String>();
		TblNbsjOuterruleEntity info = tblNbsjOuterruleService.findByid(id);
		
		map.put("repdesc", info.getBodyinfo());
		String fileName =info.getRulename()+".doc";
		
		String FREEMARKER_PATH = request.getSession().getServletContext().getRealPath("/template/doc");
		Boolean flag =(Boolean)FreeMarkerUtil.htmlFileHasExist(request, FREEMARKER_PATH, fileName).get("exist");
		if(!flag){//如何静态文件不存在，重新生成
			FreeMarkerUtil.createHtml(freeMarkerConfig, "static.ftl", request, map, FREEMARKER_PATH, fileName);//根据模板生成静态页面
		}
		String fileName1 = FREEMARKER_PATH +"/"+ fileName;
		FileUtil.downLoad(fileName1, response, false, fileName);
		FileUtil.deleteFile(fileName);
	}
    @RequestMapping(value = "/org/hy_left", method = {RequestMethod.POST})
    @ApiOperation(value = "行业树")
    @ApiOperationSupport(order = 60)
    public String orgHy_Left(HttpServletRequest request) {
        String result = null;
        List<TblOrganization> tree = tblOrganizaService.getHyOrgTree();
        TblOrganization org = tblOrganizaService.getHY();
        Map<String, Object> resultMap = new HashMap<String, Object>(0);

        resultMap.put("tree", tree);
        resultMap.put("orgid", org.getOrgid());
        resultMap.put("treeName", org.getOrgname());
        resultMap.put("targetFrame", "mainFramex");
        JSONObject json = new JSONObject(resultMap);
        result = json.toString();
        return result;
    }
    
    
    
    
    @RequestMapping(value = "/getOtherarticlePageList", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation("行业知识库-列表页")
    @ApiOperationSupport(order = 61)
    public JsonBean getOtherarticlePageList(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
   		@ApiParam(name="pageNumber",value="分页当前页数",required=false)@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
   		@ApiParam(name="pageSize",value="每页记录数",required=false)@RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
   		TblOtherarticleVo tblOtherarticleVo) {
    	JsonBean jsonBean = null;
    	
    	try {
			jsonBean = tblOtherarticleService.selectOtherarticlePageInfo(token,pageNumber,pageSize,tblOtherarticleVo);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
    @RequestMapping(value = "/mergeOtherarticle", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "行业知识库-新增、修改")
    @ApiOperationSupport(order = 62)
	public JsonBean mergeOtherarticle(HttpServletRequest request
			,@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token
			,@ApiParam(name="attIds",value="附件主键数组 示例1,2,3,4",required=false) @RequestParam(value="attIds", required = false) String attIds
			,@ApiParam(name="article",value="知识库实体",required=true)TblOtherarticle tblOtherarticle)throws Exception{
		 JsonBean jsonBean = null;
			try {
				jsonBean = tblOtherarticleService.mergeOtherarticleInfo(tblOtherarticle,token,attIds);
			} catch (Exception e) {
				ResponseFormat.retParam(1,1000,e.getMessage());
			}
			return jsonBean;
	}
    @RequestMapping(value = "/selectOtherarticleInfo", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "行业知识库-查询单个信息")
    @ApiOperationSupport(order = 63)
    public JsonBean selectOtherarticleInfo(HttpServletRequest request
    		,@ApiParam(name="othartid",value="主键",required=true) @RequestHeader("othartid")String othartid)throws Exception{
    	JsonBean jsonBean = null;
    	try {
    		jsonBean = this.tblOtherarticleService.selectInfo(othartid);
    	} catch (Exception e) {
    		ResponseFormat.retParam(1,1000,e.getMessage());
    	}
    	return jsonBean;
    }
    @RequestMapping(value = "/deleteOtherarticleInfo", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "行业知识库-删除")
    @ApiOperationSupport(order = 64)
    public JsonBean deleteOtherarticleInfo(HttpServletRequest request
    		,@ApiParam(name="othartid",value="主键",required=true) @RequestHeader("othartid")String othartid)throws Exception{
    	JsonBean jsonBean = null;
    	try {
    		jsonBean = this.tblOtherarticleService.deleteInfo(othartid);
    	} catch (Exception e) {
    		ResponseFormat.retParam(1,1000,e.getMessage());
    	}
    	return jsonBean;
    }
    
    @RequestMapping(value = "/getInnerRulePageList", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation("管理制度-列表页")
    @ApiOperationSupport(order = 71)
    public JsonBean getInnerRulePageList(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="pageNumber",value="分页当前页数",required=false)@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
    		@ApiParam(name="pageSize",value="每页记录数",required=false)@RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
    		TblNbsjInnerRuleVo tblNbsjInnerRuleVo) {
    	JsonBean jsonBean = null;
    	try {
    		jsonBean = tblNbsjInnerRuleService.selectInnerrulePageInfo(token,pageNumber,pageSize,tblNbsjInnerRuleVo);
    	} catch (Exception e) {
    		e.printStackTrace();
    	}
    	return jsonBean;
    }
    @RequestMapping(value = "/mergeInnerRule", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "管理制度-新增、修改")
    @ApiOperationSupport(order = 72)
    public JsonBean mergeInnerRule(HttpServletRequest request
    		,@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token
    		,@ApiParam(name="attIds",value="附件主键数组 示例1,2,3,4",required=false) @RequestParam(value="attIds", required = false) String attIds
    		,@ApiParam(name="tblNbsjInnerrule",value="管理制度",required=true)TblNbsjInnerrule tblNbsjInnerrule
       		,@ApiParam(name="pulishdate",value="生效日期 格式年-月-日",required=false)@RequestParam(value = "pulishdate", required = false) String pulishdate)throws Exception{
    	JsonBean jsonBean = null;
    	try {
    		jsonBean = tblNbsjInnerRuleService.mergeInnerruleInfo(tblNbsjInnerrule,token,attIds,pulishdate);
    	} catch (Exception e) {
    		ResponseFormat.retParam(1,1000,e.getMessage());
    	}
    	return jsonBean;
    }
    @RequestMapping(value = "/selectInnerRuleInfo", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "管理制度-查询单个信息")
    @ApiOperationSupport(order = 73)
    public JsonBean selectInnerRuleInfo(HttpServletRequest request
    		,@ApiParam(name="innerid",value="主键",required=true) @RequestHeader("innerid")String innerid)throws Exception{
    	JsonBean jsonBean = null;
    	try {
    		jsonBean = this.tblNbsjInnerRuleService.selectInfo(innerid);
    	} catch (Exception e) {
    		ResponseFormat.retParam(1,1000,e.getMessage());
    	}
    	return jsonBean;
    }
    @RequestMapping(value = "/deleteInnerRuleInfo", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "管理制度-删除")
    @ApiOperationSupport(order = 74)
    public JsonBean deleteInnerRuleInfo(HttpServletRequest request
    		,@ApiParam(name="innerid",value="主键",required=true) @RequestHeader("innerid")String innerid)throws Exception{
    	JsonBean jsonBean = null;
    	try {
    		jsonBean = this.tblNbsjInnerRuleService.deleteInfo(innerid);
    	} catch (Exception e) {
    		ResponseFormat.retParam(1,1000,e.getMessage());
    	}
    	return jsonBean;
    }
    
    /**
     * 管理制度-附件删除
     */
    @GetMapping("/deleteInnerRuleAtt")
    @ApiOperation(value = "管理制度-附件删除")
    public R deleteInnerRuleAtt(HttpServletRequest request, HttpServletResponse response,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="attId",value="附件主键ID",required=true) @RequestParam("attId") String attId) throws Exception {
    	return this.tblNbsjInnerRuleService.removeAttInfoByAttId(token, attId);
    }
    
	/**
	 * 管理制度-导出
	 * @param request
	 * @param response
	 * @param id
	 * @throws Exception
	 */
	@RequestMapping(value = "/expInnerRuleFile", produces = "application/json; charset=utf-8", method = {RequestMethod.GET})
    @ApiOperation(value = "管理制度-导出")
    @ApiOperationSupport(order = 74)
	public void expInnerRuleFile(HttpServletRequest request, HttpServletResponse response,
			@ApiParam(name="id",value="主键",required=true) @RequestHeader("id")String id)throws Exception{
		Map<String, String> map = new HashMap<String,String>();
		TblNbsjInnerrule info = this.tblNbsjInnerRuleService.getInfo(id);
		
		map.put("repdesc", info.getBodyinfo());
		String fileName =info.getRulename()+".doc";
		
		String FREEMARKER_PATH = request.getSession().getServletContext().getRealPath("/template/doc");
		Boolean flag =(Boolean)FreeMarkerUtil.htmlFileHasExist(request, FREEMARKER_PATH, fileName).get("exist");
		if(!flag){//如何静态文件不存在，重新生成
			FreeMarkerUtil.createHtml(freeMarkerConfig, "static.ftl", request, map, FREEMARKER_PATH, fileName);//根据模板生成静态页面
		}
		String fileName1 = FREEMARKER_PATH +"/"+ fileName;
		FileUtil.downLoad(fileName1, response, false, fileName);
		FileUtil.deleteFile(fileName);
	}
    @RequestMapping(value = "/getGkProjectInfo", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation("项目情况分析-列表页")
    @ApiOperationSupport(order = 1)
    public JsonBean getGkProjectInfo(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
   		@ApiParam(name="pageNumber",value="分页当前页数",required=false)@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
   		@ApiParam(name="pageSize",value="每页记录数",required=false)@RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
   		TblGkProjectVo project) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean=tblnbsjProjectService.getGkProjectInfo(token, pageNumber,pageSize,project);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
    @RequestMapping(value = "/getGkQuestionInfo", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation("审计问题分析-列表页")
    @ApiOperationSupport(order = 1)
    public JsonBean getGkQuestionInfo(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="pageNumber",value="分页当前页数",required=false)@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
    		@ApiParam(name="pageSize",value="每页记录数",required=false)@RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
    		TblGkQuestionVo question) {
    	JsonBean jsonBean = null;
    	try {
    		jsonBean=tblnbsjProjectService.getGkQuestionInfo(token, pageNumber,pageSize,question);
    	} catch (Exception e) {
    		e.printStackTrace();
    	}
    	return jsonBean;
    }
    @RequestMapping(value = "/getGkZgContentInfo", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation("整改问题分析-列表页")
    @ApiOperationSupport(order = 1)
    public JsonBean getGkZgContentInfo(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="pageNumber",value="分页当前页数",required=false)@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
    		@ApiParam(name="pageSize",value="每页记录数",required=false)@RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
    		TblGkZgQuestionVo question) {
    	JsonBean jsonBean = null;
    	try {
    		jsonBean=tblnbsjProjectService.getGkZgContentInfo(token, pageNumber,pageSize,question);
    	} catch (Exception e) {
    		e.printStackTrace();
    	}
    	return jsonBean;
    }
}
